package cn.wolfcode.trip.base.domain;

import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Getter
@Setter
public class TravelCommend extends BaseDomain {
    private final static Integer TYPE_WEEK = 1;
    private final static Integer TYPE_MOUTH = 2;
    private final static Integer TYPE_STRATEGY = 3;

    // 游记
    private Travel travel;
    // 标题
    private String title;
    // 副标题
    private String subTitle;
    // 封面
    private String coverUrl;
    // 推荐时间安排
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date schedule;
    // 推荐类型
    private Integer type = TYPE_WEEK;

    // 获取类型代码对应的名字
    public String getTypeName() {
        String temp = "每周推荐";
        if (type == TYPE_MOUTH) {
            temp = "每月推荐";
        } else if (type == TYPE_STRATEGY) {
            temp = "攻略推荐";
        }
        return temp;
    }

    public String getJson() {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("id", id);
        map.put("travelId", travel.id);
        map.put("title", title);
        map.put("subTitle", subTitle);
        map.put("coverUrl", coverUrl);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        map.put("schedule", sdf.format(schedule));
        map.put("type", type);
        return JSON.toJSONString(map);
    }
}